#include<iostream>
#include<string.h>
using namespace std;

const int N = 10005;
int f[N];
bool is_lost[N];
int n, m, ep;

struct EDGE
{
	int s, e;
}edges[N];

void addedge(int a, int b)
{
	edges[ep].s = a;
	edges[ep].e = b;
	ep++;
}

void init()
{
	for (int i = 1; i <= n; i++)
	{
		f[i] = i;
	}
	memset(is_lost, false, sizeof(is_lost));
}

int find(int i)
{
	if (f[i] == i)
	{
		return i;
	}
	return f[i] = find(f[i]);
}

void un(int a, int b)
{
	int fa = find(a);
	int fb = find(b);
	if (fa == fb)
	{
		return;
	}
	f[fa] = fb;
}

int uncnt()
{
	int cnt = 0;
	for (int i = 1; i <= n; i++)
	{
		if (!is_lost[i] && f[i] == i)
		{
			cnt++;
		}
	}
	return cnt;
}

int main()
{
	cin >> n >> m;
	init();
	for (int i = 0; i < m; i++)
	{
		int a, b;
		cin >> a >> b;
		addedge(a, b);
		un(a, b);
	}
	int k;
	cin >> k;
	while (k--)
	{
		init();
		int cnt;
		cin >> cnt;
		for (int i = 0; i < cnt; i++)
		{
			int city;
			cin >> city;
			is_lost[city] = true;
		}
		for (int i = 0; i < m; i++)
		{
			if (!is_lost[edges[i].s] && !is_lost[edges[i].e])
			{
				un(edges[i].s, edges[i].e);
			}
		}
		int nowcnt = uncnt();
		if (nowcnt == (n - cnt))
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
	return 0;
}